const fetchConfig = {
    baseURL: "http://demonuxtapi.dishait.cn/pc",
    headers: {
        appid: "bd9d01ecc75dbbaaefce",
        token: window.localStorage.getItem("token") ? window.localStorage.getItem("token") : ""
    }
}
function useGetFetchOptions(options = {}) {
    options.baseURL = options.baseURL ?? fetchConfig.baseURL;
    options.headers = fetchConfig.headers;
    options.data = options.data;
  
    // options.initialCache= options.initialCache ?? false;
    // options.lazy=options.lazy ?? false

    return options
}
export async function useHttp(key, url, options = {}) {
    options = useGetFetchOptions(options);
    options.key = key;
console.log( window.localStorage.getItem("token"))
console.log(url,'url')
    console.log(options, "options")
    options.headers.token = window.localStorage.getItem("token") ? window.localStorage.getItem("token"):'';
    let res = await useFetch(url, {
        ...options,
        //响应拦截器
        transform: (res) => {
            console.log(res, "resss")
            return res.data
        }
    })
    console.log(res, "resss")
    return res;

}
//get请求
export function useHttpGet(key, url, options = {}) {
    options.method = "GET"
    return useHttp(key, url, options)
}
//post请求
export function useHttpPost(key, url, options = {}) {
    options.method = "POST"
    return useHttp(key, url, options)
}